package app.fugema.shop.main.home.vm;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.lifecycle.MutableLiveData;
import app.fugema.shop.main.goods.model.CateGoodsPageBean;
import app.fugema.shop.main.goods.model.GoodsSearchParams;
import app.fugema.shop.main.home.model.HotSearchBean;
import app.fugema.shop.main.home.model.SearchGoodsBean;

import com.base.common.netBeanPackage.LiveDataWrapper;
import com.base.common.utils.UIUtils;
import com.base.common.viewmodel.BaseViewModel;
import app.fugema.shop.http.HttpService;

import java.util.HashMap;
import java.util.Map;

public class SearchVM extends BaseViewModel
{


    public SearchVM(@NonNull Application application)
    {
        super(application);
    }

    /**
     *  搜索关键词历史
     * @return
     */
    public MutableLiveData<LiveDataWrapper<HotSearchBean>> hotSearchKeyWord()
    {
        //send(HttpService.getHttpServer().hotSearch(8))
        return null;
    }


    /**
     * 搜索页面 关键词搜索 （ 只能搜索商品 ）缺少搜索店铺
     * @param searchParams
     * @return
     */
    public MutableLiveData<LiveDataWrapper<CateGoodsPageBean>> searchByKeyWord(GoodsSearchParams searchParams)
    {
        Map<String, Object> map = new HashMap<>();

        map.put("pageno", searchParams.getPageno());
        map.put("pagesize", searchParams.getPagesize());

        if( UIUtils.isNotEmpty(searchParams.getOrderkey()) && searchParams.getOrderkey() != 0  )
        {
            //排序项（1：默认，2：销量，3：价格，4：评论数，5：上架时间）
            map.put("orderkey", searchParams.getOrderkey());
        }
        if( UIUtils.isNotEmpty(searchParams.getOrdertype()) && searchParams.getOrdertype() != 0  )
        {
            // 排序方式（1：升序，2：降序）
            map.put("ordertype", searchParams.getOrdertype());
        }
        if( UIUtils.isNotEmpty(searchParams.getKeywords()) )
        {
            map.put("keywords", searchParams.getKeywords());
        }
        if( UIUtils.isNotEmpty(searchParams.getExp_keywords()) )
        {
            map.put("exp_keywords", searchParams.getExp_keywords());
        }
        if( UIUtils.isNotEmpty(searchParams.getUserkey()) )
        {
            map.put("userkey", searchParams.getUserkey());
        }

      return  send(HttpService.getHttpServer().getGoodsByParam(map));
    }


}
